﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using System.Collections.Generic;



public partial class setEmail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ////检查登录
        //cyly.AuthLogin();
        //string Act = cyly.GetUrlParaValues("Act");


        //this.lb_username.Text = cyly.getSystemLogin();


        //if (Act == "newEmail")
        //{
        //    this.tb_timeout.Text = "60";
        //    this.isNewEmail_Div.Visible = false;



        //}
        //else
        //{


        //#region 载入内容
        //if (!IsPostBack)
        //{
        //    string getCmd = "select * from setting where [SuserName]=@UserName";

        //    AccessDatabase ad = new AccessDatabase();
        //    OleDbDataReader reader = ad.ExeSql(getCmd, (new OleDbParameter[] { ad.createParamter("@UserName", cyly.getSystemLogin()) }));
        //    string senderName = "";
        //    string subject = "";
        //    string body = "";
        //    string smtp1 = "";
        //    string smtp2 = "";
        //    string smtp3 = "";
        //    string smtp4 = "";
        //    string smtp5 = "";
        //    string timeout = "";
        //    string sendMailType = "0";
        //    string Strings = "";
        //    while (reader.Read())
        //    {
        //        senderName = reader["senderName"].ToString();
        //        subject = reader["subject"].ToString();
        //        body = reader["body"].ToString();
        //        smtp1 = reader["smtp1"].ToString();
        //        smtp2 = reader["smtp2"].ToString();
        //        smtp3 = reader["smtp3"].ToString();
        //        smtp4 = reader["smtp4"].ToString();
        //        smtp5 = reader["smtp5"].ToString();
        //        timeout = reader["timeout"].ToString();
        //        sendMailType = reader["sendMailType"].ToString();
        //        Strings = reader["stringS"].ToString();
        //    }
        //    reader.Close();//DataReader
        //    //加入email body
        //    this.tb_subject.Value = subject;
        //    this.tb_body.Text = body;
        //    this.tb_senderName.Text = senderName;
        //    string[] ArrStrings = cyly.SplitString(Strings, ",");
        //    if (ArrStrings.Length == 3)
        //    {
        //        this.tb_string1.Text = ArrStrings[0].ToString();
        //        this.tb_string2.Text = ArrStrings[1].ToString();
        //        this.tb_string3.Text = ArrStrings[2].ToString();
        //    }

        //    //加入email smtp
        //    string[] ASmtp1 = cyly.SplitString(smtp1, "|");
        //    if (ASmtp1.Length >= 0)
        //        this.tb_mailset_1_1.Text = ASmtp1[0];
        //    if (ASmtp1.Length >= 1)
        //        this.tb_mailset_1_2.Text = ASmtp1[1];
        //    if (ASmtp1.Length >= 2)
        //        this.tb_mailset_1_3.Text = ASmtp1[2];
        //    string[] ASmtp2 = cyly.SplitString(smtp2, "|");
        //    if (ASmtp2.Length >= 0)
        //        this.tb_mailset_2_1.Text = ASmtp2[0];
        //    if (ASmtp2.Length >= 1)
        //        this.tb_mailset_2_2.Text = ASmtp2[1];
        //    if (ASmtp2.Length >= 2)
        //        this.tb_mailset_2_3.Text = ASmtp2[2];
        //    string[] ASmtp3 = cyly.SplitString(smtp3, "|");
        //    if (ASmtp3.Length >= 0)
        //        this.tb_mailset_3_1.Text = ASmtp3[0];
        //    if (ASmtp3.Length >= 1)
        //        this.tb_mailset_3_2.Text = ASmtp3[1];
        //    if (ASmtp3.Length >= 2)
        //        this.tb_mailset_3_3.Text = ASmtp3[2];
        //    string[] ASmtp4 = cyly.SplitString(smtp4, "|");
        //    if (ASmtp4.Length >= 0)
        //        this.tb_mailset_4_1.Text = ASmtp4[0];
        //    if (ASmtp4.Length >= 1)
        //        this.tb_mailset_4_2.Text = ASmtp4[1];
        //    if (ASmtp4.Length >= 2)
        //        this.tb_mailset_4_3.Text = ASmtp4[2];
        //    string[] ASmtp5 = cyly.SplitString(smtp5, "|");
        //    if (ASmtp5.Length >= 0)
        //        this.tb_mailset_5_1.Text = ASmtp5[0];
        //    if (ASmtp5.Length >= 1)
        //        this.tb_mailset_5_2.Text = ASmtp5[1];
        //    if (ASmtp5.Length >= 2)
        //        this.tb_mailset_5_3.Text = ASmtp5[2];

        //    this.tb_timeout.Text = timeout;

        //    if (sendMailType == "1")
        //        this.RadioButton2.Checked = true;
        //}
        //#endregion
        //   }

    }


    protected void Button1_Click(object sender, EventArgs e)
    {



        //string updateCmd = "Update setting set subject='" + this.tb_subject.Value.ToString() + "',body='" + this.tb_body.Text.ToString() + "',senderName='" + this.tb_senderName.Text + "',stringS='" + this.tb_string1.Text + "," + this.tb_string2.Text + "," + this.tb_string3.Text + "' where SuserName='" + cyly.getSystemLogin() + "'";

        ////Response.Write(updateCmd);
        //AccessDatabase ad = new AccessDatabase();
        //ad.ExeSql(updateCmd);
        //this.Label1.Text = "<span class=s1>恭喜你!修改成功!</span><script>setTimeout(function(){document.all['" + this.Label1.ClientID + "'].innerHTML='';},3000);fu_C(1);</script>";


    }


    protected void Button2_Click(object sender, EventArgs e)
    {

        //string mailset_1_1 = this.tb_mailset_1_1.Text.ToString();
        //string mailset_1_2 = this.tb_mailset_1_2.Text.ToString();
        //string mailset_1_3 = this.tb_mailset_1_3.Text.ToString();
        //string mailset_2_1 = this.tb_mailset_2_1.Text.ToString();
        //string mailset_2_2 = this.tb_mailset_2_2.Text.ToString();
        //string mailset_2_3 = this.tb_mailset_2_3.Text.ToString();
        //string mailset_3_1 = this.tb_mailset_3_1.Text.ToString();
        //string mailset_3_2 = this.tb_mailset_3_2.Text.ToString();
        //string mailset_3_3 = this.tb_mailset_3_3.Text.ToString();
        //string mailset_4_1 = this.tb_mailset_4_1.Text.ToString();
        //string mailset_4_2 = this.tb_mailset_4_2.Text.ToString();
        //string mailset_4_3 = this.tb_mailset_4_3.Text.ToString();
        //string mailset_5_1 = this.tb_mailset_5_1.Text.ToString();
        //string mailset_5_2 = this.tb_mailset_5_2.Text.ToString();
        //string mailset_5_3 = this.tb_mailset_5_3.Text.ToString();

        //string timeout = this.tb_timeout.Text.ToString();
        //string sendMailType = this.RadioButton1.Checked ? "0" : "1";

        //if (string.IsNullOrEmpty(mailset_1_1) || string.IsNullOrEmpty(mailset_1_2) || string.IsNullOrEmpty(mailset_1_3))
        //{
        //    this.Label1.Text = "<span class=s2>默认邮局必填!</span><script>fu_C(2);</script>";
        //}
        //else
        //{

        //    string sql_1 = "smtp1='" + mailset_1_1 + "|" + mailset_1_2 + "|" + mailset_1_3 + "'";
        //    string sql_2 = "smtp2='" + mailset_2_1 + "|" + mailset_2_2 + "|" + mailset_2_3 + "'";
        //    string sql_3 = "smtp3='" + mailset_3_1 + "|" + mailset_3_2 + "|" + mailset_3_3 + "'";
        //    string sql_4 = "smtp4='" + mailset_4_1 + "|" + mailset_4_2 + "|" + mailset_4_3 + "'";
        //    string sql_5 = "smtp5='" + mailset_5_1 + "|" + mailset_5_2 + "|" + mailset_5_3 + "'";

        //    string sql_6 = "timeout='" + timeout + "',sendMailType='" + sendMailType + "'";

        //    string updateCmd = "update setting set " + sql_1 + "," + sql_2 + "," + sql_3 + "," + sql_4 + "," + sql_5 + "," + sql_6 + " where SuserName='" + cyly.getSystemLogin() + "'";
        //    AccessDatabase ad = new AccessDatabase();
        //    ad.ExeSql(updateCmd);
        //    this.Label1.Text = "<span class=s1>恭喜你!修改成功!</span><script>fu_C(2);setTimeout(function(){document.all['" + this.Label1.ClientID + "'].innerHTML='';},3000)</script>";
        //}


    }



    protected void Button3_Click(object sender, EventArgs e)
    {
        //if (cyly.getSystemLogin() == "admin")
        //{
        //    string userName = this.tb_userName.Value.ToString().Trim();
        //    string passWord = this.tb_passWord.Text.ToString().Trim();


        //    if (userName.Length < 4)
        //        this.Label1.Text = "<span class=s2>请输入正确的帐户名,帐户名长度至少4个字符!</span><script>fu_C(0);</script>";
        //    else if (passWord.Length < 4)
        //        this.Label1.Text = "<span class=s2>请输入正确的密码,密码长度至少4个字符!</span><script>fu_C(0);</script>";
        //    else
        //    {
        //        AccessDatabase ad = new AccessDatabase();
        //        string getCmd = "select count(*) as Num from setting where SuserName='" + userName + "'";
        //        OleDbDataReader reader = ad.ExeSql(getCmd);
        //        if (reader.Read())
        //        {
        //            if (Convert.ToInt32(reader["Num"]) > 0)
        //            {
        //                this.Label1.Text = "<span class=s2>该帐户已经存在!</span><script>fu_C(0);</script>";
        //            }
        //            else
        //            {

        //                //添加新帐户
        //                string insertCmd = "Insert into setting(SuserName,SpassWord,stringS,senderName,subject,smtp5,smtp4,smtp3,smtp2,smtp1,timeout) values('" + userName + "','" + cyly.Md5(passWord, 32) + "','|||,|||,|||','','','||','||','||','||','||','60')";
        //                ad.ExeSql(insertCmd);
        //                this.Label1.Text = "<span class=s1>恭喜你!添加成功,请使用新帐户登录之后设置邮件内容.</span><script>fu_C(0);setTimeout(function(){document.all['" + this.Label1.ClientID + "'].innerHTML='';},3000)</script>";
        //            }
        //        }
        //        reader.Close();

        //    }



        //}
        //else
        //    this.Label1.Text = "<span class=s2>你无权限添加帐户!</span><script>fu_C(0);</script>";


    }




    protected void Button5_Click(object sender, EventArgs e)
    {
        ////删除帐户

        //if (cyly.getSystemLogin() != "admin")
        //{

        //    try
        //    {
        //        AccessDatabase ad = new AccessDatabase();
        //        string delCmd = "delete from setting where SuserName='" + cyly.getSystemLogin() + "'";
        //        ad.ExeSql(delCmd);

        //        SessionCustom.Del("UserName");
        //        this.Label1.Text = "删除成功!";
        //        cyly.MsgBox("请重新登录!", "parent.location.href='default.aspx'", 1);

        //    }
        //    catch
        //    {
        //        this.Label1.Text = "<span class=s2>系统错误!删除失败!</span>";
        //    }

        //}
        //else
        //    this.Label1.Text = "<span class=s2>帐户<b>admin</b>不能删除!</span><script>fu_C(0);</script>";

    }



}
